Archive for December 2008


TOC 2 - Nondeterministic DFAs

December 29th, 2008 — 01:39 pm

Recall from the last TOC entry that we defined DFAs and the languages that they recognized.  I know that I promised to elaborate on the Pumping Lemma today, but I figured that Nondeterminism would be more interesting, and would also be a less awkward segue into the remaining topics in this model of computation.  In addition, nondeterminism is a very important idea in itself, and is used very often with other models of computation.  In fact, in the P vs NP problem, the “N” stands for “Nondeterministic”.  Of course, in that case, we would be working with nondeterministic Turing Machines, but the idea of nondeterminism is essentially unchanged.

Nondeterminism

A Nondeterministic Finite Automata (NFA) is similar to a DFA, with two major differences:

  • The transition arrows of an NFA can be labelled with the special symbol \epsilon.  These are essentially blank “branching” symbols, and cause the NFA to “branch” into multiple copies of itself.  Recall that when we simulate a DFA on an input, we keep track of the current state, read in the next symbol, follow the transition arrow labelled with that symbol, and move to the state that the arrow leads to.  In an NFA, when we are at a state that has arrows labelled \epsilon, we “split” into different copies of the machine in which we follow each of those \epsilon arrows.  Then, if any of those copies of the NFA accepts the string, then the NFA accepts.  Equivalently, denote “keeping track of the current state” by marking the current state.  Then, the current states of an NFA are all the marked states.  If any marked state has an arrow with a \epsilon label, we follow the arrow and label that state as well.  When this \epsilon-marking is done, we read in the next symbol of the input, and move our state markers as appropriate.  This is basically a “parallel” program.
  • In a DFA, given a state q, there must be an outgoing arrow from q that is labeled with every symbol in the input alphabet.  This condition is not neccesary for an NFA.  For example, say that a marked node has no arrows leading out of it.  Then, when we read in the next input symbol, that node will become unmarked, and no new nodes will be marked.  That “branch” of the computation is essentially allowed to “die”.  In addition, states may have multiple outgoing arrows with the same label.  If state q has arrows leading to x and y that are both labeled 0, then reading 0 while q is marked will mean that both x and y will be marked next.  This is equivalent to branching on \epsilon.

The nondeterministic branching can be viewed as a type of “guessing” action by the NFA.  It tries to guess the correct paths to go down, and accepts if one of those is accepting.  We can illustrate this with the following NFA:


As you can see, it accepts all strings that contain a “11″ or a “101″ somewhere.

It’s generally easier to define NFA’s to accept a certain language L than to define a DFA to do it.  After all, NFAs can do everything that a DFA can, with the additional possibility of guessing branches.  However, it turns out that the class of languages that NFAs and DFAs recognize is the same - that is, for every DFA, there is an equivalent NFA that recognizes the same language (and vice versa).  One direction of this conversion is obvious: given a DFA, the equivalent NFA is the same as the DFA.  However, we have to show that for an arbitrary NFA, we can construct a DFA to recognize the exact same language.   This is more difficult.

Theorem: Given an NFA N = \{Q, \sigma, \delta, q_0, F\}, there exists a DFA D = \{ Q', \sigma ' , \delta ' , q'_0, F' \} such that L(N) = L(D), where L(A) where A is an automaton denotes the language recognized by A.

Proof:  We can approach this by construction.  We will simply construct a DFA that recognizes the same language as the NFA.  Let Q' be the power set of Q; that is, the set of all the subsets of Q.  This move should give you a good idea of where we’re going.  Say that we are running N on some input, and have states Q_0 marked.  When we read the next symbol, we move the markers on all those states, until we have another set of marked states, Q_1 that are marked.  But this defines our transition function exactly!  Given a subset of states in the NFA, our transition function in the DFA will, upon reading a symbol, transition to the set of states that would have resulted from feeding that symbol into the NFA.  The start state will simply be the sub containing the start state of the NFA, and the accept states F' will be all the subsets that contain at least one accept state in the NFA.  It is easy to see that this DFA will then recognize the same language as the given NFA.

This equivalence of DFA and NFA will come in use next time, when we talk about Regular Expressions, and some of their properties.  Until then, a few problems to whet your appetite for NFA fun!

- Give an NFA that recognizes {w | w ends with 00}

- Give an NFA that recognizes { w | w contains even number of 0s, or exactly two 1s} (using only six states)

2 comments » | Academia, TOC

Rar!

December 26th, 2008 — 07:17 pm

(6:14:20 PM) David: rar
(6:14:55 PM) penned in green: rwar!
(6:15:09 PM) penned in green: not to be confused with 7z
(6:15:13 PM) penned in green: zip
(6:15:21 PM) penned in green: *or zip

Hahahaha I LOVE IT

1 comment » | Uncategorized

It’s the season (of grace coming out of the void)

December 25th, 2008 — 05:08 pm

Christmas has snuck up on me once again this year, this time in the guise of my little brother waking me up with one of his new Nerf guns.  He got this really big one with a clip and a laser scope.  That is to say, the gun has a little module that says “red laser”, but pressing the “on” switch doesn’t do anything… so I’m not sure what it’s good for.   It might need batteries, but it is not immediately obvious where the batteries would go (what kind of user interface is that?).  At any rate, we proceeded to have a nerf duel across the house (I got the big gun =D ).  It ended up with us shooting each other quite a few times at point blank.  It’s like Cops and Robbers, except now both sides have laser scopes (that don’t work).  Isn’t that what Christmas is all about?

1 comment » | Uncategorized

TOC 1- Finite State Machines

December 23rd, 2008 — 03:43 pm

This will be the first post in what I hope will be a long-lived and educational series about the Theory of Computation.    I took a course in for this past term, and enjoyed it immensely.  The material is relatively straightforward, so I hope you guys will enjoy and learn from it.  Also, while I will try to be knowledgeable and accurate with my presentation, it’s very likely that I will make mistakes, so please point them out if you spot any, and I’ll be sure to acknowledge those.

In this series, I want to go over 3 things: models of computation, computability, and complexity.  Models of computation is about the different theoretical models of computers that we have.  They range from the very simple finite state machine to the Turing Machine, which are upper bounds on the capabilities of any computer we can build.  Computability deals with the types of problems that certain models of computation can solve, and whether they can be decided (the machine will give an answer in a finite amount of time).  Finally, Complexity Theory deals with solvable problems, and the amount of time and space needed for a machine to solve these things.  This is where the famous P = NP problem is from, and is a very active area of research.

Now that we have an idea of where we’re going, let’s start with…

Deterministic Finite Automata

A Deterministic Finite Automata (DFA) is a finite state machine that takes in a string input, and either “accepts” or “rejects” the input. Formally, it is defined by a 5-tuple (Q, \sum , \delta, q_0 , F).  They are defined as follows:

  • Q is the set of states of the DFA.  At each point in time, we are at one state in the machine.  As we read in symbols from the input, we transition to different states.  After the entire string is read, if we end on an “accept” state, the machine accepts - otherwise, it “rejects”.
  • \sum is the input alphabet of the machine.  In other words, it is a set of symbols that the machine can take in, and make appropriate state transitions based on the input.  Usually, the choice of alphabet does not matter too much, and we use \{ 0, 1 \}, because you can encode any alphabet into those two symbols anyway.  However, when we get into nondeterminism (which we’ll do shortly), we can also take another symbol, the empty string \epsilon, which can’t be encoded by 1 and 0.
  • \delta is the transition function of the DFA.  It is a function \delta : Q \times \sum \rightarrow Q; given a state and a symbol of the input alphabet, it tells what state to transition to.
  • q_0 is the start state of the machine.  When reading an input, you start from this state.
  • F is the set of accept states of the DFA.  If we end on one of these states after the entire input is read, then the machine accepts.

Sounds simple enough, right?  In fact, because they’re just a collection of states and transitions, DFAs are very easy to visualize in drawn form.  For example, the following is a graphical depiction of a DFA:

With this notation, the circles are the states, and the arrows are the transitions between states.  The state with the arrow pointing to it (A) is the start state, and the symbols above the transition arrows give the symbols that cause that transition.  In a DFA, each state must have an outgoing arrow associated with every symbol in the alphabet.  Also, states with an extra inner circle (C) are “accept” states.  In this example, the automata above will accept all binary strings that start with 1.

Given a DFA M and that accepts w, we say that M recognizes w.  The set of all strings that M recognizes is called its Language.
As you can imagine, DFA’s are pretty limited in the languages that they can recognize.   This can be explored in something called the Pumping Lemma, which we’ll explore next time….

Until then, some problems for the readers to work on!  Can you design DFA’s to…

- recognize strings with an odd number of 1’s

-Detect if two numbers a and b, sum to a third number, c.  You may assume that they’re encoded in binary.

Have fun, guys!

3 comments » | Academia, TOC

Testing

December 21st, 2008 — 02:07 am

x^2 = 1

Latex Works!

Now that it’s finally working, I’m wondering if I should keep on writing from this blog, or if I should create something on Wordpress.com.  I mean, it’s nice to be able to dig into my blog if I need, but really, it’ll be much easier to let the Wordpress people take care of things.  Also, by the time I graduate and lose my Athena space, I’ll no longer have this anyway.  So what should I do?

2 comments » | Uncategorized

Fourteen points

December 5th, 2008 — 02:10 pm

- Looking at pictures makes me want to learn photography.  Well-done photographs are gorgeous.  There’s a seminar in photography that Eva was in this term.  It was 6 units long, they met once a week, and they did some pretty fantastic work.  I’ve always wanted to learn to use a dark room - college seems like prime time to do so.

- It doesn’t actually take that much time to work out every day, yet I have a habit of rarely doing so, in the middle of the school year.  I really should, if only to maintain a better level of mental acuity.

- I don’t have Latex set up with this yet.  When I do, I want to start writing about my favorite subject this term (6.840 - Theory of Computation).  I plan to follow the course closely, starting with models of computation, then moving on to complexity, reductions, and some cutting-edge research in Complexity!

- My room would be really awesome if it had a bean bag chair.  I would never get up again.

- There is something about being in libraries that is so very soothing.  I love this ambiance.

- I should brush up on my QM.

- Eva has recently squeezed the idea of joining Dance Troupe into my head.  The problem?  I’ve planned an awfully busy semester next term, and also want to be a part of Next Act again.  Oh, bother!

- Heroes is a very topsy-turvy series.  I kind of liked it when I started watching (about four episodes ago), but the writers seem to have a case of OC syndrome.  I really hope they get their act together and make a coherent storyline, because at this point, the only good thing about the show is Hiro.

- I should put that sketchbook that I bought at the beginning of the year to good use.

- There is always enough time to do kind deeds for strangers.  Why don’t we all go out, wave at our neighbors, and smile for them?

- When I was little, I used to play basketball every day.  I had a Scottie Pippen #33 ball, and I would shoot free throws.  I had a ritual: spin the ball twice in my hands, raise, and shoot.

- What would happen if you tried to impose algebraic structure to language?  Say, take a language as a set, let the set of words be generators, define relations, equivalence classes, and the like.

- I have this habit of narrating my life, like I were the hero of some epic book or novel.  When I was little, I would pretend I was Batman.  My dad had this light blue bath robe, and I would take it at night, and run around the apartment.  I lieu of bad guys, I fought the couch in the living room.  It usually won.

- The first few notes to the theme of Somewhere in Time are hopelessly beautiful.  I feel like falling to pieces when I hear it.

I think that’ll do for today.  Until next time, my friends.

2 comments » | Uncategorized